package com.zhijian.medical.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.format.FastDateFormat;
import com.zhijian.medical.config.CommonConfig;
import com.zhijian.medical.entity.vo.request.FileSaveOrUpdateVo;
import com.zhijian.medical.entity.vo.request.SkillTrainingSaveOrUpdateVo;
import com.zhijian.medical.entity.vo.request.SkillTrainingSearchVo;
import com.zhijian.medical.entity.vo.response.CodeVo;
import com.zhijian.medical.entity.vo.response.SkillTrainingVo;
import com.zhijian.medical.service.SkillTrainingService;
import com.zhijian.medical.service.impl.PersonTrainTestServiceImpl;
import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 技能培训-医师诊断分级授权（变更）申请表 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-08-22 13:24:54
 */
@Slf4j
@Controller
@Api(tags = "技能培训-医师诊断分级授权（变更）申请表")
public class SkillTrainingController {

    @Autowired
    private SkillTrainingService service;

    @Autowired
    private CommonConfig commonConfig;

    /**
     * 获取最新编号们
     *
     * @return
     */
    @Response
    @GetMapping("/skill/training/code")
    @ApiOperation("获取最新编号们")
    public CodeVo getNewCode() {
        CodeVo codeVo = new CodeVo();
        codeVo.setCode2(service.createNextCode());
        codeVo.setCode(PersonTrainTestServiceImpl.CODE_PREFIX);
        codeVo.setDw(commonConfig.getDw());
        codeVo.setVersion("D/0");
        codeVo.setSaveTime("3年");
        codeVo.setZrr("文件管理员");
        codeVo.setPublishDate(DateUtil.format(new Date(), FastDateFormat.getInstance("yyyy年MM月dd日")));
        codeVo.setExecuteDate(codeVo.getPublishDate());
        return codeVo;
    }

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/skill/training")
    @ApiOperation("新增")
    public boolean insert(@RequestBody SkillTrainingSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.save(param);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/skill/training/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/skill/training/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody SkillTrainingSaveOrUpdateVo param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.modify(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/skill/training/{id}")
    @ApiOperation("根据id查询")
    public SkillTrainingVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/skill/training/page")
    @ApiOperation("分页查询")
    public Page<SkillTrainingVo> selectByCondition(@RequestBody(required = false) SkillTrainingSearchVo param) {
        if (param == null)
            param = SkillTrainingSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/skill/training/list")
    @ApiOperation("列表查询")
    public List<SkillTrainingVo> selectList(@RequestBody(required = false) SkillTrainingSearchVo param) {
        if (param == null)
            param = SkillTrainingSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectList(param);
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    @Response
    @DeleteMapping("/skill/training/list")
    @ApiOperation("批量删除")
    public boolean delete(@RequestBody(required = false) List<Long> idList) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), idList);
        service.deleteByIdList(idList);
        return true;
    }

    /**
     * 保存上传的照片
     *
     * @param fileSaveOrUpdateVos
     * @return
     */
    @Response
    @PutMapping("/skill/training/pic/{id}")
    @ApiOperation("保存上传的照片")
    public boolean savePic(@PathVariable("id") Long id, @RequestBody List<FileSaveOrUpdateVo> fileSaveOrUpdateVos) {
        return service.savePic(id, fileSaveOrUpdateVos);
    }

}